package com.api.user.controller;
import com.api.common.EmailUtil;
import com.api.core.controller.Ctrl;
import com.api.core.response.Result;
import com.api.core.response.ResultGenerator;
import com.api.user.model.Report;
import com.api.user.model.UserInfo;
import com.api.user.service.ReportService;
import com.api.user.service.UserInfoService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.security.core.Authentication;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import tk.mybatis.mapper.entity.Condition;
import tk.mybatis.mapper.entity.Example;
import javax.annotation.Resource;
import java.util.List;
import com.api.core.annotation.PowerEnable;
import io.swagger.annotations.*;



/**
* Created by wanghuiwen on 2021/04/20.
*/
@PowerEnable(name = "问题报告",url = "/report")
@Api(value = "问题报告", tags = {"问题报告"})
@RestController
@RequestMapping("/report")
public class ReportController extends Ctrl{
    @Resource
    private ReportService reportService;
    @Resource
    private UserInfoService userInfoService;

    @ApiOperation(value = "问题报告添加", tags = {"问题报告"}, notes = "问题报告添加")
    @PostMapping(value="/add",name="问题报告添加")
    public Result add(@ApiParam Report report, Authentication authentication) {
        Result result = reportService.add(report);
        if(result.getCode()  == 200){
            UserInfo info = userInfoService.findById(getAuthUser(authentication).getId());
            EmailUtil.gmailSender(info.getEmail(),"Thank you for your feedback on this matter, we will revert to you as soon as possible !",null);
        }
        return result;
    }

    @ApiOperation(value = "管理端-问题报告处理", tags = {"问题报告"}, notes = "管理端-问题报告处理")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "reportId", value = "报告id", dataType = "String", paramType = "query"),
            @ApiImplicitParam(name = "remark", value = "备注", dataType = "String", paramType = "query")

    })
    @PostMapping(value="/fix",name="管理端-问题报告处理")
    public Result fix(@RequestParam(defaultValue = "") Long reportId,@RequestParam(defaultValue = "") String remark) {

        return reportService.fix(reportId,remark);
    }

    @ApiOperation(value = "问题报告列表信息", tags = {"问题报告"}, notes = "问题报告列表信息")
    @ApiImplicitParams({
        @ApiImplicitParam(name = "search", value = "查询条件json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "order", value = "排序json", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "page", value = "页码", dataType = "String", paramType = "query"),
        @ApiImplicitParam(name = "size", value = "每页显示的条数", dataType = "String", paramType = "query", defaultValue = "10")
    })
    @PostMapping(value = "/list", name = "问题报告列表信息")
    public Result list(@RequestParam(defaultValue = "{}") String search,
                       @RequestParam(defaultValue = "{}") String order,
                       @RequestParam(defaultValue = "0") Integer page,
                       @RequestParam(defaultValue = "10") Integer size) {
        return reportService.list(search, order, page, size);
    }
}
